package pojo;

import java.io.Serializable;
import java.util.Arrays;

/**
 * 因为要在网络中传输，所以要实现Serializable接口
 */
public class NetData implements Serializable {
    /**
     * 要实现的类名
     */
    private String className;
    /**
     * 要实现的方法名
     */
    private String functionName;
    /**
     * 参数数组
     */
    private Object[] parameters;
    /**
     * 参数类型数组
     */
    private Class<?>[] parameterTypes;
    /**
     * 方法结果
     */
    private Object result;
    /**
     * 报错信息
     */
    private String msg;
    /**
     * 异常类的码
     */
    private long code;

    /**
     * 存放类的信息
     *
     * @param className      类名
     * @param functionName   代理的方法名
     * @param parameters     参数列表
     * @param parameterTypes 参数的类型列表
     */
    public NetData(String className, String functionName, Object[] parameters, Class<?>[] parameterTypes) {
        this.className = className;
        this.functionName = functionName;
        this.parameters = parameters;
        this.parameterTypes = parameterTypes;
    }

    public NetData(String msg, long code) {
        this.msg = msg;
        this.code = code;
    }

    public NetData(Object result, String msg, long code) {
        this.result = result;
        this.msg = msg;
        this.code = code;
    }

    public NetData(Object result) {
        this.result = result;
        this.code = 0L;
    }

    public void setResultAndCode(Object result) {
        this.result = result;
        this.code = 0L;
    }

    public void setMsgAndCode(String msg, long code) {
        this.msg = msg;
        this.code = code;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getFunctionName() {
        return functionName;
    }

    public void setFunctionName(String functionName) {
        this.functionName = functionName;
    }

    public Object[] getParameters() {
        return parameters;
    }

    public void setParameters(Object[] parameters) {
        this.parameters = parameters;
    }

    public Class<?>[] getParameterTypes() {
        return parameterTypes;
    }

    public void setParameterTypes(Class<?>[] parameterTypes) {
        this.parameterTypes = parameterTypes;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public long getCode() {
        return code;
    }

    public void setCode(long code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return "NetData{" +
                "className='" + className + '\'' +
                ", functionName='" + functionName + '\'' +
                ", parameters=" + Arrays.toString(parameters) +
                ", parameterTypes=" + Arrays.toString(parameterTypes) +
                ", result=" + result +
                ", msg='" + msg + '\'' +
                ", code=" + code +
                '}';
    }
}
